<?php


	/**
	 * Shortcode: column
	 *
	 * @param array $atts Shortcode attributes
	 * @param string $content
	 * @return string Output html
	 */
	function cv_column_shortcode( $atts, $content = null ) {
		extract( shortcode_atts( array(
				'size' => '1-2',
				'last' => 'false'				
				), $atts ) );

		return ( $last == 'true') ? '<div class="cv-column cv-column-' . $size . ' cv-column-last">' . do_shortcode( $content ) . '</div><div class="cv-spacer"></div>' : '<div class="cv-column cv-column-' . $size . '">' . do_shortcode( $content ) . '</div>';
	}

	/**
	 * Shortcode: list
	 *
	 * @param array $atts Shortcode attributes
	 * @param string $content
	 * @return string Output html
	 */
	function cv_list_shortcode( $atts, $content = null ) {
		extract( shortcode_atts( array(
				'style' => 'star'
				), $atts ) );
		
		return '<div class="cv-list cv-list-style-' . $style . '">' . do_shortcode( $content ) . '</div>';
	}

	/**
	 * Shortcode: quote
	 *
	 * @param array $atts Shortcode attributes
	 * @param string $content
	 * @return string Output html
	 */
	function cv_quote_shortcode( $atts, $content = null ) {
		extract(shortcode_atts(array(
			'name' => '',
			'sitename' => '',
			'siteurl' => '',
			'avatar' => ''
		), $atts));
		
		$output = '<div class="cv-quote"><div class="cv-quote-inner"><p class="cv-quote-text">';
		
		if($avatar)
			$output .= '<img class="cv-avatar" src="'.$avatar.'" alt="" />';
		
		$output .= do_shortcode($content). '</p><p class="cv-quote-from">';
	   
		if($name)
			$output .= '~ <span class="cv-fn">'.$name.'</span>';
		
		if($siteurl && $sitename)
			$output .= ', <a class="cv-su" href="'.$siteurl.'"><span class="cv-sitename">'.$sitename.'</span></a>';
		elseif($sitename)
			$output .= ', <span class="cv-sn">'.$sitename.'</span>';

	   $output .= '</p></div></div>';
	   
	   return $output;
	}

	/**
	 * Shortcode: toggle
	 *
	 * @param array $atts Shortcode attributes
	 * @param string $content
	 * @return string Output html
	 */
	function cv_toggle_shortcode( $atts, $content = null ) {
		extract( shortcode_atts( array(
				'title' => __( 'Click To Open', 'shortcodes-cv' ),
				'color' => ''
				), $atts ) );
			
		return '<div class="cv-toggle cv-toggle-open cv-toggle-' . $color . '"><div class="cv-toggle-title">' . $title . '</div><div class="cv-toggle-content">' . do_shortcode( $content ) . '</div></div>';
	}

	/**
	 * Shortcode: button
	 *
	 * @param array $atts Shortcode attributes
	 * @param string $content
	 * @return string Output html
	 */
	function cv_button_shortcode( $atts, $content = null ) {
		extract(shortcode_atts(array(
		'color' => '',
		'url' => '#',
		'value' => 'button'
		), $atts));
		
		if($color)
			$class = 'cv-button cv-button-'.$color;
		else
			$class = 'cv-button';
		
		$output = '<a href="'.$url.'" class="'.$class.'"><span class="cv-button-text">'.$value.'</span><span class="cv-button-right"></span></a>';
		
		return $output;
	}
	
	/**
	 * Shortcode: tabs
	 *
	 * @param array $atts Shortcode attributes
	 * @param string $content
	 * @return string Output html
	 */
	function cv_tabs_shortcode( $atts, $content ) {
		extract( shortcode_atts( array(
				'style' => 'horizontal'
				), $atts ) );

		$GLOBALS['tab_count'] = 0;

		do_shortcode( $content );

		if ( is_array( $GLOBALS['tabs'] ) ) {
			foreach ( $GLOBALS['tabs'] as $tab ) {
				$tabs[] = '<span>' . $tab['title'] . '</span>';
				$panes[] = '<div class="cv-tabs-pane">' . $tab['content'] . '</div>';
			}
			$return = '<div class="cv-tabs cv-tabs-style-' . $style . '"><div class="cv-tabs-nav">' . implode( '', $tabs ) . '</div><div class="cv-tabs-panes">' . implode( "\n", $panes ) . '</div><div class="cv-spacer"></div></div>';
		}
		return $return;
	}

	/**
	 * Shortcode: tab
	 *
	 * @param array $atts Shortcode attributes
	 * @param string $content
	 * @return string Output html
	 */
	function cv_tab_shortcode( $atts, $content ) {
		extract( shortcode_atts( array( 'title' => 'Tab %d' ), $atts ) );
		$x = $GLOBALS['tab_count'];
		$GLOBALS['tabs'][$x] = array( 'title' => sprintf( $title, $GLOBALS['tab_count'] ), 'content' => do_shortcode( $content ) );
		$GLOBALS['tab_count']++;
	}
	
	/**
	 * Shortcode: spacer
	 *
	 * @param array $atts Shortcode attributes
	 * @param string $content
	 * @return string Output html
	 */
	function cv_spacer_shortcode( $atts, $content = null ) {
		extract( shortcode_atts( array(
				'size' => 0
				), $atts ) );

		return '<div class="cv-spacer" style="height:' . $size . 'px"></div>';
	}
	
	/**
	 * Shortcode: gmap
	 *
	 * @param array $atts Shortcode attributes
	 * @param string $content
	 * @return string Output html
	 */
	function cv_gmap_shortcode( $atts, $content = null ) {
		extract( shortcode_atts( array(
				'width' => 600,
				'height' => 400,
				'address' => 'Singapore, Marina bay'
				), $atts ) );

		return '<iframe width="' . $width . '" height="' . $height . '" src="http://maps.google.com/maps?q=' . urlencode( $address ) . '&amp;output=embed" class="cv-gmap"></iframe>';
	}
	
?>